<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增论坛用户')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-user-add" name="form-user-add">

        <div class="form-group">
            <label class="col-sm-2 control-label">用户名称：</label>
            <div class="col-sm-10">
                <input id="userName" name="userName" class="form-control" type="text" required>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">用户图像：</label>
            <div class="col-sm-10">
                <input id="userImage" name="userImage" class="form-control" type="text" required>
                <br/>
                <div class="row">
                    <div class="col-md-6">
                        <input type="file" name="file" id="file" accept="image/*"/>
                    </div>
                    <div class="col-md-2">
                        <button id="uploadUserImageBtn" type="button" class="btn btn-primary">上传</button>
                    </div>
                    <div class="col-md-4">
                        <img width="32px" height="32px" id="userImagePreview" name="userImagePreview" th:src="@{/ruoyi.png}"/>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">账号：</label>
            <div class="col-sm-10">
                <input id="account" name="account" class="form-control" type="text" required>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">密码：</label>
            <div class="col-sm-10">
                <input id="password" name="password" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">邮箱：</label>
            <div class="col-sm-10">
                <input id="email" name="email" class="form-control" type="text" required>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">性别：</label>
            <div class="col-sm-10">
                <div class="radio-box">
                    <input type="radio" id="sex_0" name="sex" value="0" checked="checked">
                    <label for="sex_0">女</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="sex_1" name="sex" value="1">
                    <label for="sex_1">男</label>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">用户类型：</label>
            <div class="col-sm-10">
                <div class="radio-box">
                    <input type="radio" id="userType_0" name="userType" value="0" checked="checked">
                    <label for="userType_0">普通用户</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="userType_1" name="userType" value="1">
                    <label for="userType_1">终身会员</label>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">状态：</label>
            <div class="col-sm-10">
                <div class="radio-box">
                    <input type="radio" id="status_0" name="status" value="0" checked="checked">
                    <label for="status_0">正常</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="status_1" name="status" value="1">
                    <label for="status_1">关闭</label>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "bbs/user";
    $("#form-user-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-user-add').serialize());
        }
    }

    //上传图标
    $("#uploadUserImageBtn").on("click", function () {
        var file = document["form-user-add"].file.files[0];
        sendFile(file);
    });

    // 上传文件
    function sendFile(file) {
        var data = new FormData();
        data.append("file", file);
        $.ajax({
            type: "POST",
            url: ctx + "common/upload",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'json',
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $("#userImage").val(result.url);
                    $("#userImagePreview").attr("src", result.url);
                } else {
                    $.modal.alertError(result.msg);
                }
            },
            error: function (error) {
                $.modal.alertWarning("图片上传失败。");
            }
        });
    }
</script>
</body>
</html>
